<HTML> 
<HEAD> 
	<TITLE>3rd Party ROBOTC Drivers</TITLE> 
<link href="tabs.css" rel="stylesheet" type="text/css"/> 
<link href="doxygen.css" rel="stylesheet" type="text/css"/> 
</HEAD> 
 
<BODY bgcolor="#ffffff" link="#000000" vlink="#000000"> 
<table width="100%" bgcolor="navy" cellspacing=0 cellpadding=1 border=0> 
<tr><td><table width="100%" bgcolor="#EEEEDD" cellspacing=0 cellpadding=3 border=0> 
<tr> 
    <td width="33%" align="left"> <img src="images/LOGO_NXT.gif" width=266 height=44 border="0" alt="Mindstorms"></td> 
    <td><b><font size="+3" color="navy">3rd Party ROBOTC Drivers</font></b></td> 
    <td align="right"> <img src="images/logo.png" width=44 height=44 border="0" alt="RobotC"></td>     
</tr> 
  <tr bgcolor="#cccc99" align="right"> 
          <td colspan=3> <font face="arial" size="-1"> [<a href=main.html>Home</a>] [<a target=_top href="https://sourceforge.net/projects/rdpartyrobotcdr/">Download</a>] [<a target=_top href="http://apps.sourceforge.net/mantisbt/rdpartyrobotcdr/my_view_page.php">Submit a bug/suggestion</a>]  [<a target=_top href="http://www.robotc.net/forums/">ROBOTC Forums</a>] [<a target=_top href="http://botbench.com">Blog</a>] [<a target=_top href="http://sourceforge.net/donate/index.php?group_id=257238">Support this project</a>]</font> </td> 
</tr> 
</table></td></tr> 
</table> 
<!-- Generated by Doxygen 1.7.2 -->
<div class="header">
  <div class="headertitle">
<h1>dexterind-dlight-test1.c</h1>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><span class="preprocessor">#pragma config(Sensor, S1,     DLIGHT,         sensorI2CCustomFastSkipStates)</span>
<span class="preprocessor"></span><span class="comment">//*!!Code automatically generated by &#39;ROBOTC&#39; configuration wizard               !!*//</span>

<span class="comment">/*</span>
<span class="comment"> * $Id: dexterind-dlight-test1.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
<span class="comment"></span>
<span class="comment">/**</span>
<span class="comment"> * dexterind-dlight.h provides an API for the Dexter In Angle Sensor.  This program</span>
<span class="comment"> * demonstrates how to use that API.</span>
<span class="comment"> *</span>
<span class="comment"> * Changelog:</span>
<span class="comment"> * - 0.1: Initial release</span>
<span class="comment"> *</span>
<span class="comment"> * Credits:</span>
<span class="comment"> * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.</span>
<span class="comment"> *</span>
<span class="comment"> * License: You may use this code as you wish, provided you give credit where it&#39;s due.</span>
<span class="comment"> *</span>
<span class="comment"> * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. </span>
<span class="comment"></span>
<span class="comment"> * Xander Soldaat (xander_at_botbench.com)</span>
<span class="comment"> * date 31 November 2012</span>
<span class="comment"> * version 0.1</span>
<span class="comment"> */</span>

<span class="preprocessor">#include &quot;<a class="code" href="dexterind-dlight_8h.html" title="Dexter Industries dLight Sensor Driver.">drivers/dexterind-dlight.h</a>&quot;</span>


task main()
{
  <span class="keywordtype">int</span> max = 200;

  <span class="comment">// Initialise all of the dLights</span>
  <a name="a0"></a><a class="code" href="group___d_l_i_g_h_t.html#ga9b38e1a9f1f9f48b2b991557173d3f22">DLIGHTinit</a>(DLIGHT, <a name="a1"></a><a class="code" href="group___d_l_i_g_h_t.html#gad40dfbf8fd60f076eb4a59b452b78c70">DLIGHT_I2C_ADDR_ALL</a>);
  wait1Msec(50);

  <span class="comment">// Make all the lights white</span>
  <a name="a2"></a><a class="code" href="group___d_l_i_g_h_t.html#ga2c9399e5d19346ee2cb380d53ea64588">DLIGHTsetColor</a>(DLIGHT, <a class="code" href="group___d_l_i_g_h_t.html#gad40dfbf8fd60f076eb4a59b452b78c70">DLIGHT_I2C_ADDR_ALL</a>, 0xFF, 0xFF, 0xFF);
  wait1Msec(1000);

  <span class="comment">// Make all of the lights red</span>
  <a class="code" href="group___d_l_i_g_h_t.html#ga2c9399e5d19346ee2cb380d53ea64588">DLIGHTsetColor</a>(DLIGHT, <a class="code" href="group___d_l_i_g_h_t.html#gad40dfbf8fd60f076eb4a59b452b78c70">DLIGHT_I2C_ADDR_ALL</a>, 0xFF, 0, 0);
  wait1Msec(1000);

  <span class="comment">// Make all of the lights...green</span>
  <a class="code" href="group___d_l_i_g_h_t.html#ga2c9399e5d19346ee2cb380d53ea64588">DLIGHTsetColor</a>(DLIGHT, <a class="code" href="group___d_l_i_g_h_t.html#gad40dfbf8fd60f076eb4a59b452b78c70">DLIGHT_I2C_ADDR_ALL</a>, 0, 0xFF, 0);
  wait1Msec(1000);

  <span class="comment">// Make all of the lights, you guessed it, red, no wait, blue!</span>
  <a class="code" href="group___d_l_i_g_h_t.html#ga2c9399e5d19346ee2cb380d53ea64588">DLIGHTsetColor</a>(DLIGHT, <a class="code" href="group___d_l_i_g_h_t.html#gad40dfbf8fd60f076eb4a59b452b78c70">DLIGHT_I2C_ADDR_ALL</a>, 0, 0, 0xFF);
  wait1Msec(1000);


  <span class="comment">// Make a nice sort of rainbow effect by cycling through colours</span>
  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> value = 0; value &lt; max; value++)
  {
                <span class="keywordtype">int</span> midpoint = max / 2;
                <span class="keywordtype">int</span> currvalue = max - value;
                <span class="keywordtype">int</span> red = 0;
                <span class="keywordtype">int</span> green = 0;
                <span class="keywordtype">int</span> blue = 0;

                <span class="keywordflow">if</span> (currvalue &lt;= midpoint)
                {
                        red = 255 - ((255 / midpoint) * currvalue);
                        green = (255 / (midpoint) * currvalue);
                        blue = 0;
                }
                <span class="keywordflow">else</span>
                {
                        red = 0;
                        green = 255 - ((255 / midpoint) * (currvalue - midpoint));
                        blue = 255 / (midpoint) * (currvalue - (midpoint));
                }
                <span class="keywordflow">if</span> (red &lt; 0 || red &gt; 255)
                        red = 0;
                <span class="keywordflow">if</span> (green &lt; 0 || green &gt; 255)
                        green = 0;
                <span class="keywordflow">if</span> (blue &lt; 0 || blue &gt; 255)
                        blue = 0;
    <a class="code" href="group___d_l_i_g_h_t.html#ga2c9399e5d19346ee2cb380d53ea64588">DLIGHTsetColor</a>(DLIGHT, <a class="code" href="group___d_l_i_g_h_t.html#gad40dfbf8fd60f076eb4a59b452b78c70">DLIGHT_I2C_ADDR_ALL</a>, red, green, blue);
    wait1Msec(50);
  }

  <span class="comment">// Make the lights blink!</span>
  <span class="comment">// Configure for 1 Hz with a 10% duty rate</span>
  <a name="a3"></a><a class="code" href="group___d_l_i_g_h_t.html#gad9879c5d36f5bf1431df3ad1b6762a6e">DLIGHTsetBlinking</a>(DLIGHT, <a class="code" href="group___d_l_i_g_h_t.html#gad40dfbf8fd60f076eb4a59b452b78c70">DLIGHT_I2C_ADDR_ALL</a>, 1, 10);
  wait1Msec(10);

  <span class="comment">// Set the colour</span>
  <a class="code" href="group___d_l_i_g_h_t.html#ga2c9399e5d19346ee2cb380d53ea64588">DLIGHTsetColor</a>(DLIGHT, <a class="code" href="group___d_l_i_g_h_t.html#gad40dfbf8fd60f076eb4a59b452b78c70">DLIGHT_I2C_ADDR_ALL</a>, 0, 0xFF, 0xFF);
  wait1Msec(10);

  <span class="comment">// Start blinking!</span>
  <a name="a4"></a><a class="code" href="group___d_l_i_g_h_t.html#ga0e70287b7282bf3c96198082f0407817">DLIGHTstartBlinking</a>(DLIGHT, <a class="code" href="group___d_l_i_g_h_t.html#gad40dfbf8fd60f076eb4a59b452b78c70">DLIGHT_I2C_ADDR_ALL</a>);
  wait1Msec(5000);

  <span class="comment">// Stop the blinking</span>
  <a name="a5"></a><a class="code" href="group___d_l_i_g_h_t.html#ga895816790d36646339b06ece22ec09df">DLIGHTstopBlinking</a>(DLIGHT, <a class="code" href="group___d_l_i_g_h_t.html#gad40dfbf8fd60f076eb4a59b452b78c70">DLIGHT_I2C_ADDR_ALL</a>);
  wait1Msec(10);

  <span class="comment">// Turn off all of the</span>
  <a name="a6"></a><a class="code" href="group___d_l_i_g_h_t.html#gad3cb2007e046233a88861338bdd7ce7a">DLIGHTdisable</a>(DLIGHT, <a class="code" href="group___d_l_i_g_h_t.html#gad40dfbf8fd60f076eb4a59b452b78c70">DLIGHT_I2C_ADDR_ALL</a>);

  <span class="comment">//DLIGHTsetColor(DLIGHT, DLIGHT_I2C_ADDR_1, 0xFF, 0, 0);</span>
  <span class="comment">//wait1Msec(500);</span>
  <span class="comment">//DLIGHTstartBlinking(DLIGHT, DLIGHT_I2C_ADDR_1);</span>
  <span class="comment">//DLIGHTsetColor(DLIGHT, DLIGHT_I2C_ADDR_2, 0, 0xFF, 0);</span>
  <span class="comment">//wait1Msec(500);</span>
  <span class="comment">//DLIGHTstartBlinking(DLIGHT, DLIGHT_I2C_ADDR_2);</span>
  <span class="comment">//DLIGHTsetColor(DLIGHT, DLIGHT_I2C_ADDR_3, 0, 0, 0xFF);</span>
  <span class="comment">//wait1Msec(500);</span>
  <span class="comment">//DLIGHTstartBlinking(DLIGHT, DLIGHT_I2C_ADDR_3);</span>
  <span class="comment">//DLIGHTsetColor(DLIGHT, DLIGHT_I2C_ADDR_4, 0xFF, 0xFF, 0xFF);</span>
  <span class="comment">//wait1Msec(500);</span>
  <span class="comment">//DLIGHTstartBlinking(DLIGHT, DLIGHT_I2C_ADDR_4);</span>
  <span class="comment">//wait1Msec(2000);</span>
  <span class="comment">//DLIGHTstopBlinking(DLIGHT, DLIGHT_I2C_ADDR_ALL);</span>
}
</pre></div> </div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Mar 13 2013 19:56:41 for ROBOTC Drivers by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
